package com.jiandaoshou.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.andview.refreshview.recyclerview.BaseRecyclerAdapter;
import com.jiandaoshou.R;
import com.jiandaoshou.entry.CardInfo;
import com.jiandaoshou.utils.LogUtil;

import java.util.List;

/**
 * Created by Administrator on 2016/9/29.
 */

public class YinHangKaAdapter extends BaseRecyclerAdapter<YinHangKaAdapter.MyViewHolder>{
    public Context context;
    public List<CardInfo> datas;

    public YinHangKaAdapter(Context context, List<CardInfo> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public MyViewHolder getViewHolder(View view) {
        return new MyViewHolder(view);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_yinhangka, parent, false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position, boolean isItem) {
        int id = context.getResources().getIdentifier(datas.get(position).getStrBankIcon().toLowerCase(), "mipmap", context.getPackageName());
        holder.Img_YinHang.setImageResource(id);
        holder.YinHang_Name.setText(datas.get(position).getStrBankName());
        String zhanghao=datas.get(position).getStrCardNumber();
        if(zhanghao.length() > 4)
        holder.YinHang_ZhuangHao.setText("************"+zhanghao.substring(zhanghao.length()-4,zhanghao.length()));
        else{
            holder.YinHang_ZhuangHao.setText("************"+zhanghao);
        }
        holder.ItemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.OnListener(holder.itemView, holder.getLayoutPosition());
            }
        });
    }

    @Override
    public int getAdapterItemCount() {
        return datas.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView Img_YinHang;
        TextView YinHang_Name;
        TextView YinHang_ZhuangHao;
        View ItemView;

        public MyViewHolder(View itemView) {
            super(itemView);
            Img_YinHang = (ImageView) itemView.findViewById(R.id.icon_yinhang);
            YinHang_Name= (TextView) itemView.findViewById(R.id.tv_yinhangname);
            YinHang_ZhuangHao= (TextView) itemView.findViewById(R.id.tv_yinhangzhuanghu);
            this.ItemView = itemView;
        }
    }

    public void setOnItemListener(OnItemListener listener) {
        this.listener = listener;
    }

    OnItemListener listener;

    public interface OnItemListener {
        void OnListener(View view, int pos);
    }
}
